﻿/*
 *  PassBag is multi-platform software that securely manage/store passwords
 *  Copyright (C) <2009>  <Hugo Rodrigues PEREIRA>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *	
 *  You can find a copy of the GPLv3 at project <root directory>/gpl.txt
 *
 */

using System;

namespace PassBag.Utils {
    /// <summary>
    /// Web helper class
    /// </summary>
    public sealed class WebTools {
        /// <summary>
        /// Navigates the specified address.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <returns>True on success else false</returns>
        public static bool Navigate (string address) {
            if (! String.IsNullOrEmpty (address)) {
                // not contain about:blank
                if (! address.Contains ("about:blank")) { 
                    // add http if not present
                    if (!address.StartsWith ("http://") &&
                        !address.StartsWith ("https://")) {
                        address = string.Format ("http://{0}", address);
                    }  
              
                     try {
                         System.Diagnostics.Process.Start (address);

                        return true;
                    }
                    catch (System.UriFormatException) {
                        return false;
                    }
                }
                else {
                    return false;
                }
            }
            else {
                return false;
            }
        }
    }
}
